package com.ruoyi.framework.config;

import cn.hutool.core.util.IdUtil;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;

/**
 * @Author cailinhu
 * @Description 从库id生成器
 * @Date 2023/5/26 15:47
 * @Version 1.0
 */
public class IncrementIdGenerator implements IdentifierGenerator {
    @Override
    public Long nextId(Object entity) {
        String peek = DynamicDataSourceContextHolder.peek();
        if (peek.equals("slave")){
            System.out.println("从库");
        }else {
            System.out.println("主库");
        }
        long snowflakeNextId = IdUtil.getSnowflakeNextId();
        return snowflakeNextId;


    }
}
